//
//  FeedBackViewController.m
//  17DianYing
//
//  Created by 赵雄 on 15/9/23.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "FeedBackViewController.h"
#import "AFNetworking.h"

@interface FeedBackViewController ()
@property (weak, nonatomic) IBOutlet UITextView *feedBackView;

@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.feedBackView setDelegate:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)feedBackBUtton:(id)sender {
    
    NSString *content = [[NSString alloc]init];
    content = self.feedBackView.text;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *usertoken = [user objectForKey:@"usertoken"];
    NSLog(@"token:%@",usertoken);
    //我们使用AFHTTPRequestSerializer的POST提交方式
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString * url =[http stringByAppendingString:@"/mobile/support/postFeedback"];
    NSDictionary *dic = @{@"token":usertoken,@"content":content};
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        id obj = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        NSDictionary *dic = obj;
        
        NSLog(@"+++++++++++++++++++++++%@",dic);
        
        UIAlertView *a = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交成功" delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
        [a show];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"_________________________%@",error.localizedDescription);
    }];
}

//根据被点击按钮的索引处理点击事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"fhfdioddskxmldnjvcnv");
    [self.navigationController popToRootViewControllerAnimated:YES];
}
//textview字数限制
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if (range.location>=140)
    {
        UIAlertView * alert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"您已输入140个字" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles: nil];
        [alert show];
//        [alert release];
        return NO;
    }
    else
    {
        return YES;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
